package com.vogue.supplymall.upload.controller;

import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.vogue.supplymall.common.domain.dto.ControllerResultInfo;
import com.vogue.supplymall.common.domain.dto.UploadInfo;
import com.vogue.supplymall.common.exception.RemoveUploadException;
import com.vogue.supplymall.common.exception.UploadException;
import com.vogue.supplymall.upload.domain.service.UploadService;

@RestController
public class OrderUploadController extends BaseController{
	/**
     * The constant log.
     */
    public static final Logger LOGGER_ORDERUPLOADCONTROLLER = LoggerFactory.getLogger(OrderUploadController.class);
    @Resource
    private UploadService uploadService;

    /**
     * Upload order img response entity.
     * 上传图片
     *
     * @param appver             the appver
     * @param uploadResourceInfo the upload resource info
     * @return the response entity
     */
    @RequestMapping(value = "/is/{appver}/upload/comment/upload", method = RequestMethod.POST)
    public ResponseEntity<Object> uploadOrderImg(@PathVariable("appver") String appver,
                                                  @RequestBody UploadInfo uploadResourceInfo) {
    	System.out.println("我怎么就进不来呢");
        LOGGER_ORDERUPLOADCONTROLLER.info("upload order image start >>>>>> ");
        if (null == uploadResourceInfo.getDataid() || null == uploadResourceInfo.getPicData()
                || null == uploadResourceInfo.getExtension() || null == uploadResourceInfo.getFileName()) {
            throw new UploadException("");
        }

        ControllerResultInfo resultInfo = new ControllerResultInfo();
        resultInfo.setResult(true);
        uploadResourceInfo.setModuleName("comment");
        resultInfo.setData(uploadService.uploadResource(uploadResourceInfo));
        LOGGER_ORDERUPLOADCONTROLLER.info(" <<<<<< upload order image end");
        return new ResponseEntity<>(resultInfo, HttpStatus.OK);
    }

    /**
     * Remove order img response entity.
     * 删除图片
     *
     * @param appver             the appver
     * @param uploadResourceInfo the refund upload info
     * @return the response entity
     */
    @RequestMapping(value = "/is/{appver}/upload/comment/remove", method = RequestMethod.POST)
    public ResponseEntity<Object> removeOrderImg(@PathVariable("appver") String appver,
                                                  @RequestBody UploadInfo uploadResourceInfo) {
        LOGGER_ORDERUPLOADCONTROLLER.info("remove order image start >>>>>> ");
        if (StringUtils.isEmpty(uploadResourceInfo.getDeletePath())) {
            throw new RemoveUploadException("");
        }
        ControllerResultInfo resultInfo = new ControllerResultInfo();
        resultInfo.setResult(true);
        resultInfo.setData(uploadService.removeResource(uploadResourceInfo));
        LOGGER_ORDERUPLOADCONTROLLER.info(" <<<<<< remove order image end");
        return new ResponseEntity<>(resultInfo, HttpStatus.OK);
    }
}
